import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/indexCore/views/home/Home.vue'
const title="滋溜鹿博客"
const routes = [
  {
      path: '/', 
      name:"index",
      meta: { title:title,},
      components:{
        default:Home,
        switch:() => import('@indexCore/views/home/HomeIndex'),
      },

      // redirect:"index", //index 比较好看
    },
    // {
    //     path: '/backend',
    //     name: 'backend', 
    //     meta: { title: '后端',},
    //     components: () => import('@indexCore/views/backend/backend'),
    //    },
       {
        path: '/photograph',
        name: 'photograph', 
        meta: { title: '摄影-'+title,},
        component:() => import('@indexCore/views/photograph/photograph'),
       }, 
       {
        path: '/music',
        name: 'music', 
        meta: { title: '音乐-'+title,},
        component: () => import('@indexCore/views/music/music'),
       }, 
                {
        path:'/laboratory',
        name: 'laboratory', 
        meta: { title: '实验室-'+title,},
        components:{
          default:Home,
          switch:() => import('@indexCore/views/laboratory/laboratory'),
        } 
      },

   {
        path:'/refresh',
        name: 'refresh', 
        meta: { title: '刷新-'+title,},
        components:{
          default:Home,
          switch:() => import('@indexCore/views/refresh'),
        } 
      },
      {
        path:'/friendlink',
        name: 'friendlink', 
        meta: { title: '友链-'+title,},
        components:{
          default:Home,
          switch:() => import('@indexCore/views/friendlink/friendlink'),
        } 
      },
      
      {
        path:'/article/:id',
        name: 'article', 
        meta: { title: title,},
        components:{
          default:Home,
          switch:() => import('@indexCore/views/article/article'),
        } 
      },
      
      {
        path: '/frontend',
        name: 'frontend', 
        meta: { title: '前端-'+title,},
        components:{
          default:Home,
          switch:() => import('@indexCore/views/frontend/frontend'),
        }  
        }, 
        {
        path: '/algorithm',
        name: 'algorithm', 
        meta: { title: '后端-'+title,},
         components:{
          default:Home,
          switch:() => import('@indexCore/views/algorithm/Algorithm.vue'),
        } 
       },
      
    {
          path: '/404',
          name: '404',
          meta: { title: '404' },
          component: () => import('@indexCore/views/404'),
    },
     
    {
  path: "/*", redirect: '/404', 
    }
   
]

const router = createRouter({
   history: createWebHistory(),
  // history: createWebHashHistory(),
  routes
})


router.beforeEach((to) => {
  // to: Route: 即将要进入的目标 路由对象
  // from: Route: 当前导航正要离开的路由  
  // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
  
  // let isLogin = false 
  if (to.meta.title) {
    document.title = to.meta.title;
  }  
})

export default router
